//
//  CPNewFeatrueCell.swift
//  weibo
//
//  Created by zcp on 16/5/14.
//  Copyright © 2016年 zcp. All rights reserved.
//

import UIKit
import SnapKit
class CPNewFeatrueCell: UICollectionViewCell {
    
    var index: Int = 0{
    

        didSet{
        
            iconView.image = UIImage(named: "new_feature_\(index+1)")
            btn.transform = CGAffineTransformMakeScale(0, 0)
        }
    }
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        
        self.contentView.addSubview(iconView)
        addSubview(btn)
        //约束
        btn.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-160)
        }
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        iconView.frame = bounds
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //添加动画
    func addAnimotion(){
    
        UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 3, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.btn.transform = CGAffineTransformMakeScale(1.0, 1.0)
            }, completion: nil)
        
    }
    //按钮点击操作
    func btnClick() {
    
        //跳转到欢迎控制器
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        appDelegate.switchRootViewController(CPWelcomeViewController())
    
    }
    
    //MARK -- 懒加载控件
    lazy var iconView: UIImageView  = UIImageView(image: UIImage(named: "new_feature_1"))
    
    lazy var btn: UIButton = {
        let btn = UIButton()
        btn.setTitle("开始旅程", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
        btn.transform = CGAffineTransformMakeScale(0, 0)
        //添加事件
        btn.addTarget(self, action: "btnClick", forControlEvents: UIControlEvents.TouchUpInside)
        return btn
        }()
 

    
}
